package lapsnake.model.expr;

import lapsnake.model.*;
import lapsnake.model.data.*;
import lapsnake.py.ast.ASTHelperFactory; 
import lapsnake.ui.JTreeLabel;

import java.awt.Component;
import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for IfExp nodes*/
public class LapIfExp extends LapExpression {
	SingleChild<LapExpression> body = new SingleChild<>(this, LapExpression.class);
	SingleChild<LapExpression> test = new SingleChild<>(this, LapExpression.class);
	SingleChild<LapExpression> orelse = new SingleChild<>(this, LapExpression.class);
	
	public LapIfExp(PyAST pyAST, ChildField<? super LapIfExp> parent, IfExp node) throws PropertyVetoException {
		super(pyAST, parent, node);

		ASTHelperFactory.makeHelper(pyAST, test, node.getInternalTest());
		ASTHelperFactory.makeHelper(pyAST, body, node.getInternalBody());
		ASTHelperFactory.makeHelper(pyAST, orelse, node.getInternalOrelse());
		
		buildTextNodes(node);
	}
	
	@Override
	protected Component getFillerComponent(int childIndex,
		ChildField<?> childField)
	{

		if(childField == body)
			return new JTreeLabel("Use", false);
		else if(childField == test)
			return new JTreeLabel("if", false);
		else
			return new JTreeLabel("else", false);
	}
}
